package trying;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Intersection {
    public static void main(String[] args) {
        String str1 = "101,102";
        String str2 = "102,103";
        String[] strs1 = str1.split(",");
        for (String str:strs1) {
            if (str2.contains(str)) {
                System.out.println("交集是:"+ str);
            }
        }

        System.out.println(System.currentTimeMillis());
        String str3 = "107,108";
        String str4 = "101,102,103,104,105,106,107,";
        String[] strs2 = str3.split(",");
        String[] strs3 = str4.split(",");
        List list1 = new ArrayList(Arrays.asList(strs2));
        List list2 = new ArrayList(Arrays.asList(strs3));
        list1.retainAll(list2);
        System.out.println(list1);
        System.out.println(System.currentTimeMillis());



        System.out.println(System.currentTimeMillis());
        String ywfclist = "107,108";
        String ywfcstr = "101,102,103,104,105,106,107,";
        List<String > ywfc = new ArrayList<String>();
        String[] ywfcAry = ywfclist.split(",");
        for(int i = 0;i < ywfcAry.length;i++) {
            ywfc.add(i, ywfcAry[i]);
        }

        List<String > allywfc = new ArrayList<String>();
        ywfcAry = ywfcstr.split(",");
        for(int i = 0;i < ywfcAry.length;i++) {
            allywfc.add(i, ywfcAry[i]);
        }
        allywfc.retainAll(ywfc);
        System.out.println("==交集："+allywfc.toString());
        System.out.println(System.currentTimeMillis());

        List list4 = new ArrayList();
        list4.add(0,1);
        System.out.println(list4);
    }
}
